package com.franklin.ideaplugin.easytesting.ui.execute;

import com.franklin.ideaplugin.api.beans.DateClass;
import com.franklin.ideaplugin.api.beans.EnumClass;
import com.franklin.ideaplugin.api.beans.FileClass;
import com.intellij.psi.PsiParameter;
import org.jetbrains.annotations.NotNull;

/**
 * @author Ye Junhui
 * @since 2023/7/2 11:55
 */
public class StringParameterFormProvider implements IParameterFormProvider {

    private final IParameterFormProvider enumProvider = new EnumClassParameterFormProvider();
    private final IParameterFormProvider fileProvider = new FileClassParameterFormProvider();
    private final IParameterFormProvider dateProvider = new DateClassParameterFormProvider();
    private final IParameterFormProvider jsonProvider = new JsonParameterFormProvider();
    private final IParameterFormProvider normalProvider = new NormalParameterFormProvider();

    @Override
    public boolean isTarget(@NotNull Object defaultValue) {
        return defaultValue instanceof String;
    }

    @Override
    public ParameterTextComponent getForm(PsiParameter psiParameter, Object defaultValueOfPsiType, Object defaultValue) {
        String str = (String) defaultValue;
        if (defaultValueOfPsiType instanceof EnumClass){
            return enumProvider.getForm(psiParameter, defaultValueOfPsiType, defaultValue);
        }
        if (defaultValueOfPsiType instanceof FileClass){
            return fileProvider.getForm(psiParameter, defaultValueOfPsiType, defaultValue);
        }
        if (defaultValueOfPsiType instanceof DateClass){
            return dateProvider.getForm(psiParameter, defaultValueOfPsiType, defaultValue);
        }
        if (jsonProvider.isTarget(str)){
            return jsonProvider.getForm(psiParameter, defaultValueOfPsiType, defaultValue);
        }

        return normalProvider.getForm(psiParameter, defaultValueOfPsiType, defaultValue);
    }


}
